package com.example.demo;

import ch.qos.logback.core.util.StringUtil;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/userlogin")
public class loginController {
    @RequestMapping(value = "login",method = RequestMethod.POST)
    public Boolean login(String userName, String password, HttpSession session){
//        if(userName==null||"".equals(userName)){
//            return  false;
//        }
        if(!StringUtils.hasLength(userName)){
            return  false;
        }
        if("admin".equals(userName)&&"admin".equals(password)){
            //登入成功时要设置session
            session.setAttribute("userName",userName);

            return true;
        }
        return false;
    }
    @RequestMapping("/getLogin")
    public String getLogin(HttpSession session) {
        if (session.getAttribute("userName") != null) {
            return (String) session.getAttribute("userName");
        }
        return " ";
    }
}
